]> git.r.bdr.sh - rbdr/junction/blame - safari/Junction Extension/SafariWebExtensionHandler.swift
Update docs
[rbdr/junction] / safari / Junction Extension / SafariWebExtensionHandler.swift
CommitLineData
4a191e80
RBR
1//
2// SafariWebExtensionHandler.swift
3// Junction Extension
4//
5// Created by Ruben Beltran del Rio on 9/13/23.
6//
7
8import SafariServices
9import os.log
10
11class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
12
13 func beginRequest(with context: NSExtensionContext) {
14 let request = context.inputItems.first as? NSExtensionItem
15
16 let profile: UUID?
17 if #available(iOS 17.0, macOS 14.0, *) {
18 profile = request?.userInfo?[SFExtensionProfileKey] as? UUID
19 } else {
20 profile = request?.userInfo?["profile"] as? UUID
21 }
22
23 let message: Any?
24 if #available(iOS 17.0, macOS 14.0, *) {
25 message = request?.userInfo?[SFExtensionMessageKey]
26 } else {
27 message = request?.userInfo?["message"]
28 }
29
30 os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@ (profile: %@)", String(describing: message), profile?.uuidString ?? "none")
31
32 let response = NSExtensionItem()
33 response.userInfo = [ SFExtensionMessageKey: [ "echo": message ] ]
34
35 context.completeRequest(returningItems: [ response ], completionHandler: nil)
36 }
37
38}